package br.com.felix.easyclearcase.tasks;

import java.awt.Dialog;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * A specialized task to show a dialog and change its status to completed when the dialog is closed.
 * @see Task
 * */
public class DialogTask extends Task {

	
	private Dialog dialog;
	
	
	/**
	 * Instantiates a new dialogtask.
	 * @param dialog the dialog to be shown when the task is executed.
	 * */
	public DialogTask(Dialog dialog){
		this.dialog = dialog;
	}
	
	/**
	 * Does nothing.
	 * */
	@Override
	public void cancel() {
		// TODO Auto-generated method stub
	}


	/**
	 * Shows the dialog as a modal window.
	 * When the dialog is closed, the task status is set to complete.
	 * */
	@Override
	public void run() {
		changeStatus(TaskStatus.IN_PROGRESS);
		dialog.addWindowListener(new WindowAdapter(){
			@Override
			public void windowClosed(WindowEvent e) {
				changeStatus(TaskStatus.COMPLETE_SUCCESS);
			}
			
		});
		dialog.setModal(true);
		dialog.setVisible(true);
	}



	/**
	 * DialogTask status priority is NORMAL.
	 * */
	@Override
	public TaskPriority getTaskPriority() {
		return TaskPriority.NORMAL;
	}
}
